<template>
  <el-dialog
    :visible="visible"
    :append-to-body="true"
    title="选择设备"
    width="60%"
    @close="close"
  >
    <div class="table-page-search-wrapper">
      <el-form :inline="true" label-width="100px">
        <el-row :gutter="18">
          <el-col :md="8" :sm="24">
            <el-form-item label="设备编号">
              <el-input
                v-model="queryParam.equipmentNumber"
                placeholder=""
                clearable
                @keyup.enter.native="onSearch"
                @clear="onSearch"
              />
            </el-form-item>
          </el-col>
          <el-col :md="8" :sm="24">
            <el-form-item label="设备名称">
              <el-input
                v-model="queryParam.equipmentName"
                placeholder=""
                clearable
                @keyup.enter.native="onSearch"
                @clear="onSearch"
              />
            </el-form-item>
          </el-col>
          <template v-if="advanced">
            <el-col :md="8" :sm="24">
              <el-form-item label="设备类型">
                <el-input
                  v-model="queryParam.equipmentType"
                  placeholder=""
                  clearable
                  @keyup.enter.native="onSearch"
                  @clear="onSearch"
                />
              </el-form-item>
            </el-col>
          </template>
          <el-col :md="(!advanced && 8) || 24" :sm="24">
            <span
              class="table-page-search-submitButtons"
              :style="
                (advanced && { float: 'right', overflow: 'hidden' }) || {}
              "
            >
              <el-button
                v-waves
                type="primary"
                icon="el-icon-search"
                @click="onSearch"
              >
                查询
              </el-button>
              <el-button type="info" icon="el-icon-refresh" @click="reset">
                重置
              </el-button>
              <el-link
                type="primary"
                :underline="false"
                @click="toggleAdvanced"
              >
                {{ advanced ? "收起" : "展开" }}
                <i
                  :class="advanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
                />
              </el-link>
            </span>
          </el-col>
        </el-row>
      </el-form>
    </div>

    <div class="table-operator">
      <!-- <el-button
        v-permission="['create']"
        type="primary"
        icon="el-icon-plus"
        @click="$refs.form.open(undefined)"
      >
        新建
      </el-button> -->
    </div>

    <el-table
      ref="tableEl"
      v-loading="loadingData"
      :data="list"
      element-loading-text="Loading"
      fit
      highlight-current-row
      row-key="id"
      @sort-change="appendSorterParam"
      @selection-change="handlerSelectionChange"
    >
      <el-table-column
        align="center"
        type="selection"
        :selectable="checkSelectable"
      />
      <el-table-column align="center" label="创建时间">
        <template slot-scope="scope">
          <span>{{ scope.row.createTime }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="设备sn号">
        <template slot-scope="scope">
          <span>
            {{ scope.row.macSn }}
          </span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="设备编号">
        <template slot-scope="scope">
          <span>
            {{ scope.row.equipmentNumber }}
          </span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="设备名称">
        <template slot-scope="scope">
          <span>
            {{ scope.row.equipmentName }}
          </span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="设备型号">
        <template slot-scope="scope">
          <span>
            {{ scope.row.equipmentModel }}
          </span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="使用部门">
        <template slot-scope="scope">
          <span>
            {{ scope.row.userDepartment }}
          </span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="管理负责人">
        <template slot-scope="scope">
          <span>
            {{ scope.row.managementResponsiblePerson }}
          </span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="设备类型">
        <template slot-scope="scope">
          <span>
            {{ scope.row.equipmentType }}
          </span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="是否被占用">
        <template slot-scope="scope">
          <span>
            {{ scope.row.status==0?'未占用':'已占用' }}
          </span>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="pagination.total > 0"
      :total="pagination.total"
      :page.sync="pagination.current"
      :limit.sync="pagination.pageSize"
      :style="{ textAlign: 'right' }"
      @pagination="handlePaginationChanged"
    />
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">
        取消
      </el-button>
      <el-button type="primary" @click="onSubmit">
        确定
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
import list from '@/components/diboot/mixins/list'
import waves from '@/directive/waves'

export default {
  name: 'EquipmentModal',
  directives: { waves },
  mixins: [list],
  data() {
    return {
      baseApi: '/equipment',
      getListFromMixin: true,
      visible: false,
      selectList: []
    }
  },
  methods: {
    checkSelectable(row) {
      if (row.status === 1) {
        return false
      } else {
        return true
      }
    },
    handlerSelectionChange(val) {
      this.selectList = val
    },
    onSubmit() {
      this.$emit('OK', this.selectList)
      this.close()
    },
    open() {
      this.visible = true
    },
    close() {
      this.visible = false
      this.$refs.tableEl.clearSelection()
    }
  }
}
</script>
<style lang="scss" scoped></style>
